package avicit.bdp.dds.dao.entity;


import avicit.bdp.common.base.BaseDTO;
import avicit.platform6.core.annotation.log.FieldRemark;
import avicit.platform6.core.annotation.log.Id;
import avicit.platform6.core.annotation.log.LogField;
import avicit.platform6.core.properties.PlatformConstant;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.multipart.MultipartFile;

import javax.persistence.Column;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.List;
import java.util.Objects;

@ApiModel(value = "Resource", description = "资源对象")
@Table(name = "bdp_dds_resources")
public class Resource extends BaseDTO {

    /**
     * 文件
     */
    @Transient
    public static Integer DIRECTORY_FILE = 0;


    /**
     * 目录
     */
    @Transient
    public static Integer DIRECTORY_FOLDER = 1;

    /**
     * 文件
     */
    @Transient
    public static Integer TYPE_RESOURCE = 0;


    /**
     * UDF
     */
    @Transient
    public static Integer TYPE_UDF = 1;

    /**
     * 自定义函数
     */
    @Transient
    public static Integer DTYPE_NODE = 2;

    /**
     * id
     */
    @Id
    @LogField
    @ApiModelProperty(value = "id", name = "id")
    @FieldRemark(column = "id", field = "id", name = "主键")
    @javax.persistence.Id
    @Column(name = "id")
    private String id;

    @LogField
    @ApiModelProperty(value = "名称", name = "name")
    @FieldRemark(column = "name", field = "name", name = "名称")
    @Column(name = "name")
    private String name;

    //@LogField
    @ApiModelProperty(value = "项目ID", name = "projectId")
    //@FieldRemark(column = "project_id", field = "projectId", name = "项目ID")
    @Column(name = "project_id")
    private String projectId;

    //@LogField
    @ApiModelProperty(value = "类型：0--文件；1--udf；2--自定义节点", name = "type")
    //@FieldRemark(column = "type", field = "type", name = "类型")
    @Column(name = "type")
    private Integer type;

    //@LogField
    @ApiModelProperty(value = "文件大小", name = "size")
    //@FieldRemark(column = "size", field = "size", name = "文件大小")
    @Column(name = "size")
    private Long size;

    //@LogField
    @ApiModelProperty(value = "文件后缀", name = "fileSuffix")
    //@FieldRemark(column = "file_suffix", field = "fileSuffix", name = "文件后缀")
    @Column(name = "file_suffix")
    private String fileSuffix;

    @LogField
    @ApiModelProperty(value = "备注", name = "remark")
    @FieldRemark(column = "remark", field = "remark", name = "备注")
    @Column(name = "remark")
    private String remark;

    //@LogField
    @ApiModelProperty(value = "父ID", name = "pid")
    //@FieldRemark(column = "pid", field = "pid", name = "父ID")
    @Column(name = "pid")
    private String pid;

    //@LogField
    @ApiModelProperty(value = "全文件名", name = "fullName")
    //@FieldRemark(column = "full_name", field = "fullName", name = "全文件名")
    @Column(name = "full_name")
    private String fullName;

    //@LogField
    @ApiModelProperty(value = "是否目录 0--文件；1--目录", name = "directory")
    //@FieldRemark(column = "directory", field = "directory", name = "是否目录")
    @Column(name = "directory")
    private Integer directory;

    /**
     * 状态：0--上传中；1--上传成功；2--上传失败；3--计算中；4--计算成功；5--计算失败
     */
    //@LogField
    @ApiModelProperty(value = "状态：0--上传中；1--上传成功；2--上传失败；3--计算中；4--计算成功；5--计算失败")
    //@FieldRemark(column = "status", field = "status", name = "状态")
    @Column(name = "status")
    private Integer status;

    /**
     * 其他信息：json对象
     */
    //@LogField
    @ApiModelProperty(value = "其他信息：json对象")
    //@FieldRemark(column = "otherInfo", field = "otherInfo", name = "其他信息：json对象")
    @Column(name = "other_info")
    private String otherInfo;

    /**
     * 存储引擎ID
     */
    //@LogField
    @ApiModelProperty(value = "存储引擎ID")
    //@FieldRemark(column = "engineResourceId", field = "engineResourceId", name = "存储引擎ID")
    @Column(name = "engine_resource_id")
    private String engineResourceId;

    /**
     * 子对象集合
     */
    @Transient
    private List<Resource> children;

    /**
     * 用户名
     */
    @Transient
    private String username;

    /**
     * 文件
     */
    @Transient
    @JsonIgnore
    private MultipartFile file;

    /**
     * 文件大小带单位
     */
    @Transient
    private String sizeStr;

    @ApiModelProperty(value = "状态")
    @Transient
    private String statusString;

    public Resource() {
    }

    public Resource(String id, String name, String projectId, Integer type, Long size, String fileSuffix,
                    String remark, String pid, String fullName, Integer directory) {
        this.id = id;
        this.name = name;
        this.projectId = projectId;
        this.type = type;
        this.size = size;
        this.fileSuffix = fileSuffix;
        this.remark = remark;
        this.pid = pid;
        this.fullName = fullName;
        this.directory = directory;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getProjectId() {
        return projectId;
    }

    public void setProjectId(String projectId) {
        this.projectId = projectId;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public Long getSize() {
        return size;
    }

    public void setSize(Long size) {
        this.size = size;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getPid() {
        return pid;
    }

    public void setPid(String pid) {
        this.pid = pid;
    }

    public String getFullName() {
        return fullName;
    }

    public void setFullName(String fullName) {
        this.fullName = fullName;
    }

    public Integer getDirectory() {
        return directory;
    }

    public void setDirectory(Integer directory) {
        this.directory = directory;
    }

    public List<Resource> getChildren() {
        return children;
    }

    public void setChildren(List<Resource> children) {
        this.children = children;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public MultipartFile getFile() {
        return file;
    }

    public void setFile(MultipartFile file) {
        this.file = file;
    }

    public String getFileSuffix() {
        return fileSuffix;
    }

    public void setFileSuffix(String fileSuffix) {
        this.fileSuffix = fileSuffix;
    }

    public String getSizeStr() {
        return sizeStr;
    }

    public void setSizeStr(String sizeStr) {
        this.sizeStr = sizeStr;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getOtherInfo() {
        return otherInfo;
    }

    public void setOtherInfo(String otherInfo) {
        this.otherInfo = otherInfo;
    }

    public String getStatusString() {
        return statusString;
    }

    public void setStatusString(String statusString) {
        this.statusString = statusString;
    }

    public String getEngineResourceId() {
        return engineResourceId;
    }

    public void setEngineResourceId(String engineResourceId) {
        this.engineResourceId = engineResourceId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }

        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Resource resource = (Resource) o;
        return size.equals(resource.size) &&
                directory.equals(resource.directory) &&
                id.equals(resource.id) &&
                Objects.equals(name, resource.name) &&
                Objects.equals(projectId, resource.projectId) &&
                type.equals(resource.type) &&
                Objects.equals(remark, resource.remark) &&
                Objects.equals(pid, resource.pid) &&
                Objects.equals(fullName, resource.fullName);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name, projectId, type, size, remark, pid, fullName, directory);
    }

    @Override
    public String toString() {
        return "Resource{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", projectId='" + projectId + '\'' +
                ", type=" + type +
                ", size=" + size +
                ", fileSuffix='" + fileSuffix + '\'' +
                ", remark='" + remark + '\'' +
                ", pid='" + pid + '\'' +
                ", fullName='" + fullName + '\'' +
                ", directory=" + directory +
                ", children=" + children +
                ", username='" + username + '\'' +
                ", file=" + file +
                ", sizeStr='" + sizeStr + '\'' +
                '}';
    }

    @Override
    public String getLogFormName() {
        if (avicit.platform6.commons.utils.StringUtils.isEmpty(super.logFormName)) {
            return "文件管理模块";
        } else {
            return super.logFormName;
        }
    }

    @Override
    public String getLogTitle() {
        if (avicit.platform6.commons.utils.StringUtils.isEmpty(super.logTitle)) {
            return "文件管理";
        } else {
            return super.logTitle;
        }
    }

    @Override
    public PlatformConstant.LogType getLogType() {
        if (super.logType == null) {
            return PlatformConstant.LogType.module_operate;
        } else {
            return super.logType;
        }
    }
}
